package com.itcast.spring6.aop.api;

import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * 前置通知
 * @author zhangtian105
 * @date 2023/5/11
 * @apiNote
 */
@Slf4j
@Component(value = "myMethodBeforeAdvice")
public class MyMethodBeforeAdvice implements MethodBeforeAdvice {
    /**
     * target：目标对象
     * method：被触发目标对象的方法
     * args：目标对象的目标方法的携带的参数
     * @param method
     * @param args
     * @param target
     * @throws Throwable
     */
    @Override
    public void before(Method method, Object[] args, Object target) throws Throwable {
        String targetName = target.getClass().getName() ;
        String methodName = method.getName() ;
        String params = Arrays.toString(args) ;

        String msg = "【系统日志】：正在调用->"+targetName+"."+methodName+",携带的参数："+params;

        log.info("【Before】spring6.MyMethodBeforeAdvice.before: {}", msg);
    }
}
